// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class ORDER_OBSERVATION_OUL_R21 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("24 CONTAINER",24)]
  	    [HL7Field(HL7Version.v24, 24, HL7Repeat.False, HL7Required.False,"CONTAINER_OUL_R21")]
	    public CONTAINER_OUL_R21 CONTAINER {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("36 ORC",36)]
  	    [HL7Field(HL7Version.v24, 36, HL7Repeat.False, HL7Required.False,"ORC")]
	    public ORC ORC {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("38 OBR",38)]
  	    [HL7Field(HL7Version.v24, 38, HL7Repeat.False, HL7Required.True,"OBR")]
	    public OBR OBR {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("41 NTE",41)]
  	    [HL7Field(HL7Version.v24, 41, HL7Repeat.True, HL7Required.False,"NTE")]
	    public NTE[] NTE {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("44 OBSERVATION",44)]
  	    [HL7Field(HL7Version.v24, 44, HL7Repeat.True, HL7Required.True,"OBSERVATION_OUL_R21")]
	    public OBSERVATION_OUL_R21[] OBSERVATION {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("64 CTI",64)]
  	    [HL7Field(HL7Version.v24, 64, HL7Repeat.True, HL7Required.False,"CTI")]
	    public CTI[] CTI {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			CONTAINER = ProcessGroup<CONTAINER_OUL_R21>(availableData, options, "CONTAINER");
			ORC = PopSegmentParseAndCheckRequired<ORC>(availableData, options, "ORC");
			OBR = PopSegmentParseAndCheckRequired<OBR>(availableData, options, "OBR");
			NTE = PopSegmentParseAndCheckRequiredArray<NTE>(availableData, options, "NTE");
			OBSERVATION = ProcessGroupArray<OBSERVATION_OUL_R21>(availableData, options, "OBSERVATION");
			CTI = PopSegmentParseAndCheckRequiredArray<CTI>(availableData, options, "CTI");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			CONTAINER_OUL_R21 testCONTAINER_OUL_R21 = new CONTAINER_OUL_R21();
			bool grpCCCONTAINER_OUL_R21 = (testCONTAINER_OUL_R21.CanConsume(availableData, options));
			if (IsRequired("CONTAINER", options.Version) || grpCCCONTAINER_OUL_R21) {
				return grpCCCONTAINER_OUL_R21;
			}
			bool isORC = availableData.StartsWith("ORC", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("ORC", options.Version) || isORC) {
				return isORC;
			}
			bool isOBR = availableData.StartsWith("OBR", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("OBR", options.Version) || isOBR) {
				return isOBR;
			}
			bool isNTE = availableData.StartsWith("NTE", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("NTE", options.Version) || isNTE) {
				return isNTE;
			}
			OBSERVATION_OUL_R21 testOBSERVATION_OUL_R21 = new OBSERVATION_OUL_R21();
			bool grpCCOBSERVATION_OUL_R21 = (testOBSERVATION_OUL_R21.CanConsume(availableData, options));
			if (IsRequired("OBSERVATION", options.Version) || grpCCOBSERVATION_OUL_R21) {
				return grpCCOBSERVATION_OUL_R21;
			}
			bool isCTI = availableData.StartsWith("CTI", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("CTI", options.Version) || isCTI) {
				return isCTI;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "ORDER_OBSERVATION";
			}
        }

        static ORDER_OBSERVATION_OUL_R21() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(ORDER_OBSERVATION_OUL_R21));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (CONTAINER != null) {
			string segmentValue = CONTAINER.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (ORC != null) {
			string segmentValue = ORC.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (OBR != null) {
			string segmentValue = OBR.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (NTE != null && NTE.Length > 0) {
			for (int i = 0; i < NTE.Length; i++) {
				string segmentValue = NTE[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (OBSERVATION != null && OBSERVATION.Length > 0) {
			for (int i = 0; i < OBSERVATION.Length; i++) {
				string segmentValue = OBSERVATION[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (CTI != null && CTI.Length > 0) {
			for (int i = 0; i < CTI.Length; i++) {
				string segmentValue = CTI[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

